package de.mpii.yago;

import java.io.File;

import de.mpii.Config;
import de.mpii.struct.trie.Trie;
import de.mpii.util.Uio;

public class Database {

	private static final String PATH = Config.BASE_PATH + "/yago";

	public static Trie<String> loadClass(String klass) throws Exception {

		File dir = new File(PATH);

		File file = null;

		for (File f : dir.listFiles()) {
			if (!f.getName().contains(klass))
				continue;

			file = f;
			break;
		}

		if (file == null) {
			System.out.println(">> DATA FOR CLASS " + klass + " NOT EXIST.");
			return null;
		}

		String content = Uio.read(file);
		String[] lines = content.split("\n");

		Trie<String> trie = new Trie<String>();

		for (String s : lines) {
			String _s = s.trim();
			trie.put(_s, _s);

			System.out.println(">> ADD ENTRY [" + _s + "]");
		}

		return trie;
	}

}
